package com.siwei.mes.service.system.impl;

import com.siwei.mes.entity.system.Signature;
import com.siwei.mes.mapper.system.SignatureMapper;
import com.siwei.mes.service.system.SignatureService;
import org.springframework.stereotype.Service;
import static com.siwei.mes.common.exception.handler.MessageHandler.assertTrue;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.siwei.mes.common.query.PageQuery;

import javax.annotation.Resource;
import java.util.List;

/**
 * 打印电子签名表(Signature)表服务实现类
 *
 * @author makejava
 * @since 2025-08-31 00:02:02
 */
@Service
public class SignatureServiceImpl implements SignatureService {
    @Resource
    private SignatureMapper signatureMapper;
    
     @Override
    public Long create(Signature entity) {
        signatureMapper.insertSelective(entity);
        return entity.getId();
    }

    @Override
    public void update(Signature entity) {
        Signature signature = signatureMapper.selectByPrimaryKey(entity.getId());
        assertTrue(signature == null, "打印电子签名表信息不存在");
        signatureMapper.updateByPrimaryKeySelective(entity);
    }

    @Override
    public void delete(Long id) {
        Signature signature = signatureMapper.selectByPrimaryKey(id);
        assertTrue(signature == null, "打印电子签名表信息不存在");
        signatureMapper.deleteByPrimaryKey(id);
    }

    @Override
    public PageInfo<Signature> getPage(PageQuery<Signature, Signature> query) {
        Signature searchParam = query.getParams();  
        return PageHelper.startPage(query.getPageNum(), query.getPageSize())
                .doSelectPageInfo(() -> signatureMapper.getList(searchParam));
    }

    @Override
    public Signature loadById(Long id) {
        return signatureMapper.loadById(id);
    }

    @Override
    public List<Signature> getAll(Signature entity) {
        return signatureMapper.getList(entity);
    }
}
